package top.lyjwn.ajui.base;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.view.View;

import com.xuexiang.xui.utils.StatusBarUtils;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.actionbar.TitleUtils;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import top.lyjwn.ajui.AJUIApplication;
import top.lyjwn.ajui.R;

/**
 * 基础活动
 *
 * @author luoyujie
 */
public abstract class BaseActivity extends AppCompatActivity {

    protected Handler handler = new Handler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        StatusBarUtils.translucent(this);
        View iTitleBar = findViewById(R.id.iTitleBar);
        if (iTitleBar != null && iTitleBar instanceof TitleBar){
            ITitleBar titleBar = (ITitleBar)iTitleBar;
            String titleText = titleBar.getTitleText();

            TitleUtils.initTitleBarStyle(titleBar, titleText==null?"主页":titleText, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            if (titleText==null){
                titleBar.setLeftVisible(false);
            }
        }
        if ( AJUIApplication.getContext()==null){
            AJUIApplication.setContext(this);
        }
    }

    @Override
    protected void onResume() {
        if (AJUIApplication.getContext() == null) {
            AJUIApplication.setContext(this);
        }
        super.onResume();
    }

    @LayoutRes
    protected abstract int getLayoutId();

    protected Context getContext() {
        return this;
    }


}
